package com.moli.iov.his.util;

import com.moli.iov.his.dto.VehicleTrajectoryReqDTO;
import com.moli.iov.his.dto.VehicleTrajectoryResDTO;
import com.moli.iov.protocol.model.realtime.*;
import com.moli.iov.protocol.util.RealTimeInfoUtil;
import com.moli.iov.util.CoordTransformUtil;

/**
 * @ClassName AdapterUtil
 * @Description TODO
 * @Author 李伟松
 * @CreateDate 2019-09-09 下午 7:40
 * @UpdateDate 2019-09-09 下午 7:40
 * @Version 1.0
 */
public class AdapterUtil {

    public static VehicleTrajectoryResDTO adapterTrajectory(RealTimeInfoReq realTime){
        if (realTime!=null){
            VehicleTrajectoryResDTO dto = new VehicleTrajectoryResDTO();
            VehicleAllReq vehicleAll = realTime.getVehicleAllReq();
            if(vehicleAll!=null){
                if(vehicleAll.getGear()!=null){
                    dto.setGear(vehicleAll.getGear().getK());
                }
                dto.setSpeed(vehicleAll.getSpeed());
                dto.setSoc(vehicleAll.getSoc());
                dto.setOdometer(vehicleAll.getOdometer());
            }
            VehicleGpsReq gps = realTime.getVehicleGpsReq();
            if(realTime.getVehicleGpsReq()!=null){
                double[] tude=CoordTransformUtil.transformWGS84ToBD09(gps.getLongitude(),gps.getLatitude());
                dto.setLongitude( tude[0] );
                dto.setLatitude( tude[1] );
                if(gps.getLocationState()!=null){
                    dto.setLocationStatus(gps.getLocationState().getK());
                }
            }

            ExtendReq extendReq = realTime.getExtendReq();
            if(extendReq!=null && extendReq.getextendVehicleState()!=null){
                dto.setExtendGpsDirection(extendReq.getextendVehicleState().getExtendGpsDirection());
                if(extendReq.getextendVehicleState().getExtendPowerGear()!=null){
                    dto.setPowerGear(extendReq.getextendVehicleState().getExtendPowerGear().getK());
                }
                dto.setGpsOde(extendReq.getextendVehicleState().getExtendGpsOde());
            }

            if(realTime.getCollectDate()!=null){
                dto.setReportDate(realTime.getCollectDate().getDate());
            }
            return dto;
        }
        return null;
    }
}
